package com.zg.nacos.web;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.common.core.R;
import com.zg.nacos.domain.convert.MicroNacosConvert;
import com.zg.nacos.domain.entity.MicroNacos;
import com.zg.nacos.domain.req.MicroNacosAddReq;
import com.zg.nacos.domain.req.MicroNacosEditReq;
import com.zg.nacos.domain.req.MicroNacosPageReq;
import com.zg.nacos.domain.vo.MicroNacosVo;
import com.zg.nacos.service.MicroNacosService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/6/16 20:23
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("/micro/nacos")
@Slf4j
@Api(tags = "手动注册nacos信息")
public class MicroNacosController {

    private final MicroNacosService microNacosService;

    private final MicroNacosConvert microNacosConvert;

    @PostMapping("/page")
    public R page(@RequestBody MicroNacosPageReq pageReq) {
        Page<MicroNacosVo> page = microNacosService.page(pageReq, MicroNacosVo.class);
        return R.success(page);
    }


    @PostMapping("/add")
    public R add(@Validated @RequestBody MicroNacosAddReq addReq) {
        microNacosService.add(addReq);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@Validated @RequestBody MicroNacosEditReq editReq) {
        microNacosService.edit(editReq);
        return R.success();
    }

    @PostMapping("/remove")
    public R remove(@RequestBody  List<Long> ids) {
        microNacosService.remove(ids);
        return R.success();
    }

    @GetMapping("/list")
    public R<List<MicroNacosVo>> list() {
        List<MicroNacos> vList=microNacosService.list();
        return R.success(microNacosConvert.toVoList(vList));
    }
    @PostMapping("/start")
    public R start(@RequestBody @NotEmpty(message = "ID不能为空") List<Long> ids) {
        microNacosService.start(ids.get(0));
        return R.success();
    }
}
